package 树;

import 抽象数据类型.TreeNode;

/**
 * @author: yangwk
 * @date: 2023/4/4
 * @description:
 **/
public class 判断是否为相同的树 {
    //相同的树
    public static boolean isSameTree(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return true;
        }
        if (root1 == null || root2 == null) {
            return false;
        }
        return root1.getVal() == root2.getVal() && isSameTree(root1.left, root2.left) && isSameTree(root1.right, root2.right);
    }
}
